<template>
  <div class="myOrder">
    <div class="myOrder-header clearfloat">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/mechanism/home/menu' }"
          >首页</el-breadcrumb-item
        >
        <el-breadcrumb-item>我的订单</el-breadcrumb-item>
      </el-breadcrumb>

      <div class="btns fr">
        <el-button class="mr20" @click="toAfterKnow">国知局后：{{ afterTotal }}</el-button>
        <el-button class="mr20" @click="switchTable(2)" v-if="getType != 2"
          >案件答复：{{ myReplyTotal }}</el-button
        >
        <el-button class="mr20" @click="switchTable(1)" v-if="getType != 1"
          >我的订单：{{ myCaseTotal }}</el-button
        >
        <el-button class="mr20" @click="switchTable(3)" v-if="getType != 3"
          >案件复审：{{ myReviewTotal }}</el-button
        >
        <orderStatistics
          :myInfo="myInfo"
          :roleID="roleID"
          :getType="getType"
          @getData="headGetData"
        />
        <table-search
          v-if="getType == 1"
          class="clearfloat table-search"
          ref="table-search"
          :isGetAgent="true"
          :selectHead="getTeacherColumns"
          @searchMethods="searchMethods"
        ></table-search>
        <table-search
          v-if="getType == 2"
          class="clearfloat table-search"
          ref="table-search"
          :isGetAgent="true"
          :selectHead="selectHeadAnswer"
          @searchMethods="searchMethods"
        ></table-search>
      </div>
    </div>
    <div class="myOrder-main" ref="watermark">
      <el-table
        ref="tableRef"
        :data="tableData"
        border
        v-loading="loading"
        height="100%"
        :row-class-name="tableRowClass"
        @row-click="selectRow"
        @sort-change="tableSortChange"
      >
        <!-- 我的订单 -->
        <template v-if="getType == 1">
          <el-table-column
            show-overflow-tooltip
            label="耗时(天)"
            key="1"
            min-width="130"
            prop="pick_up_date"
            sortable="custom"
          >
            <template slot-scope="scope">
              <template v-if="scope.row.pick_up_date">
                <span
                  v-if="getProcessingTime(scope.row.pick_up_date) > 25"
                  class="font_danger"
                  >{{ getProcessingTime(scope.row.pick_up_date) }}</span
                >
                <span v-else>{{
                  getProcessingTime(scope.row.pick_up_date)
                }}</span>
              </template>
              <template v-else>
                <span
                  v-if="getProcessingTime(scope.row.created_at) > 25"
                  class="font_danger"
                  >{{ getProcessingTime(scope.row.created_at) }}</span
                >
                <span v-else>{{
                  getProcessingTime(scope.row.created_at)
                }}</span>
              </template>
            </template>
          </el-table-column>
          <el-table-column
            show-overflow-tooltip
            sortable="custom"
            key="2"
            prop="order_number"
            label="订单编号"
            min-width="180"
          ></el-table-column>
          <el-table-column
            show-overflow-tooltip
            sortable="custom"
            key="3"
            label="流程状态"
            min-width="120"
          >
            <template slot-scope="scope">
              <span :class="scope.row.status | orderStatusColor">{{
                scope.row.status
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            show-overflow-tooltip
            sortable="custom"
            key="4"
            v-if="$store.state.user.is_teacher == 2"
            prop="status"
            label="导师审核状态"
            min-width="200"
          >
            <template slot-scope="scope">
              <span>{{ scope.row | teacherAuditorStatus }}</span>
            </template>
          </el-table-column>
          <el-table-column
            show-overflow-tooltip
            sortable="custom"
            key="5"
            prop="type"
            label="专利类型"
            min-width="120"
          ></el-table-column>
          <el-table-column
            show-overflow-tooltip
            prop="patent_name"
            key="6"
            label="拟申报专利名称"
            min-width="200"
            sortable="custom"
          ></el-table-column>
          <el-table-column
            label="支付状态"
            min-width="150"
            sortable="custom"
            v-if="showOrderPay"
          >
            <template slot-scope="scope">
              <span
                style="color:green"
                v-if="scope.row.order_pay && scope.row.order_pay.pay_status"
                >{{ scope.row.order_pay | orderPay }}</span
              >
              <span style="color:red" v-else>{{
                scope.row.order_pay | orderPay
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="附图"
            min-width="150"
            sortable="custom"
            v-else
          >
            <template slot-scope="scope">
              <div v-if="scope.row.imgArr" class="img-wrap" @click.stop>
                <pre-img
                  :smallImg="scope.row.imgArr"
                  :bigImg="scope.row.imgArr2"
                  class="pre-img"
                ></pre-img>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            show-overflow-tooltip
            prop="liaisons"
            key="7"
            label="联络人"
            min-width="100"
            sortable="custom"
          >
            <template slot-scope="scope">
              <span>{{ scope.row.liaisons }}</span>
              <Tooltip
                v-if="$store.state.user.is_teacher == 1"
                content="点我留言"
              >
                <i
                  class="el-icon-chat-dot-round leaveWord"
                  @click.stop="leaveWordF(scope.row, 'l')"
                ></i>
              </Tooltip>
            </template>
          </el-table-column>
          <el-table-column
            show-overflow-tooltip
            prop="user_name"
            key="8"
            label="发明人"
            min-width="100"
            sortable="custom"
          ></el-table-column>
          <el-table-column
            show-overflow-tooltip
            prop="liaisons_tel"
            key="9"
            label="电话"
            min-width="120"
            sortable="custom"
          ></el-table-column>
          <el-table-column
            show-overflow-tooltip
            prop="liaisons_email"
            key="10"
            label="邮箱"
            min-width="180"
            sortable="custom"
          ></el-table-column>
          <el-table-column
            show-overflow-tooltip
            prop="process"
            key="11"
            label="专属顾问"
            min-width="120"
            sortable
          >
            <template slot-scope="scope">
              <span>{{ scope.row.process | processNumber }}</span>
              <Tooltip
                v-if="$store.state.user.is_teacher == 1"
                content="点我留言"
              >
                <i
                  class="el-icon-chat-dot-round leaveWord"
                  @click.stop="leaveWordL(scope.row, 'process')"
                ></i>
              </Tooltip>
            </template>
          </el-table-column>
          <el-table-column
            show-overflow-tooltip
            key="12"
            v-if="$store.state.user.is_teacher == 1"
            prop="agent"
            label="代理人"
            min-width="140"
            sortable="custom"
          >
            <template slot-scope="scope">{{
              scope.row.agent | agentNumAddName
            }}</template>
          </el-table-column>
          <!-- <el-table-column
            show-overflow-tooltip
            key="13"
            prop="opinions_count"
            label="审核次数"
            min-width="120"
            sortable="custom"
          ></el-table-column>
          <el-table-column
            prop="review_file"
            key="14"
            label="内容审核文件"
            min-width="200"
          >
            <template slot-scope="scope">
              <div class="flie-hid">
                <a
                  v-for="item in scope.row.reviewfileArr"
                  :key="item.id"
                  :href="
                    baseUrl +
                      '/api/download?path=' +
                      item.file +
                      '/' +
                      item.path
                  "
                  :download="item.path"
                  :title="item.path"
                  class="el-icon-tickets file_sh"
                  @click.stop="stopLook"
                ></a>
              </div>
            </template>
          </el-table-column> -->
          <el-table-column
            show-overflow-tooltip
            key="15"
            label="提交时间"
            prop="created_at"
            min-width="160"
            sortable
          ></el-table-column>
          <el-table-column
            show-overflow-tooltip
            key="16"
            label="修改时间"
            min-width="160"
            prop="updated_at"
            sortable
          ></el-table-column>
          <el-table-column
            show-overflow-tooltip
            key="17"
            label="接单时间"
            min-width="160"
            sortable
            prop="pick_up_date"
          ></el-table-column>
        </template>
        <!-- 我的答复 -->
        <template v-else-if="getType == 2">
          <el-table-column
            show-overflow-tooltip
            key="18"
            label="订单耗时(天)"
            prop="reply_time"
            min-width="140"
            sortable="custom"
          >
            <template slot-scope="scope">
              <span v-if="getTimeConsuming(scope.row) > 20">
                <span class="font_danger">{{
                  getTimeConsuming(scope.row)
                }}</span>
              </span>
              <span v-else>{{ getTimeConsuming(scope.row) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            show-overflow-tooltip
            key="19"
            prop="order_number"
            label="订单编号"
            min-width="180"
            sortable="custom"
          ></el-table-column>
          <el-table-column
            show-overflow-tooltip
            key="20"
            prop="status"
            label="流程状态"
            min-width="110"
            sortable="custom"
          >
            <template slot-scope="scope">{{ scope.row.status }}</template>
          </el-table-column>
          <el-table-column
            show-overflow-tooltip
            key="21"
            prop="type"
            label="专利类型"
            min-width="110"
            sortable="custom"
          >
            <template slot-scope="scope">{{
              scope.row.type | typeFilter
            }}</template>
          </el-table-column>
          <el-table-column
            show-overflow-tooltip
            key="22"
            prop="application_number"
            label="申请号"
            min-width="160"
            sortable="custom"
          ></el-table-column>
          <el-table-column
            key="23"
            show-overflow-tooltip
            prop="name"
            label="申报名称"
            min-width="180"
            sortable="custom"
          ></el-table-column>
          <el-table-column
            key="25"
            prop="opinion_file"
            label="审查意见/补正文件"
            min-width="170"
          >
            <template slot-scope="scope">
              <div class="flie-hid">
                <a
                  v-for="item in scope.row.opinionFile"
                  :key="item.id"
                  :href="
                    baseUrl +
                      '/api/download?path=' +
                      item.file +
                      '/' +
                      item.path
                  "
                  :download="item.path"
                  :title="item.path"
                  class="el-icon-tickets file_sh"
                ></a>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="answer_file"
            key="24"
            label="答复意见"
            min-width="150"
          >
            <template slot-scope="scope">
              <div class="flie-hid">
                <a
                  v-for="item in scope.row.answerFile"
                  :key="item.id"
                  :href="
                    baseUrl +
                      '/api/download?path=' +
                      item.file +
                      '/' +
                      item.path
                  "
                  :download="item.path"
                  :title="item.path"
                  class="el-icon-tickets file_sh"
                ></a>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            key="26"
            show-overflow-tooltip
            prop="status_submited_at"
            label="提交日期"
            min-width="160"
            sortable="custom"
          >
            <template slot-scope="scope">{{ scope.row | getPost }}</template>
          </el-table-column>
          <el-table-column
            key="27"
            show-overflow-tooltip
            prop="status_updated_at"
            label="更新时间"
            min-width="160"
            sortable="custom"
          >
            <template slot-scope="scope">{{
              scope.row | getAnswerUpdateTime
            }}</template>
          </el-table-column>
          <el-table-column fixed="right" width="100" label="操作">
            <template slot-scope="scope" v-if="getType == 2">
              <el-button
                type="primary"
                size="small"
                :disabled="
                  scope.row.status == '发明人确认答复中' ||
                    scope.row.status == '发明人确认补正中'
                "
                @click.stop="answer(scope.row)"
                >{{
                  scope.row.status == "等待答复" ||
                  scope.row.status == "发明人确认答复中"
                    ? "答复"
                    : "补正"
                }}</el-button
              >
            </template>
          </el-table-column>
        </template>
        <template v-else>
          <el-table-column
            show-overflow-tooltip
            key="22"
            prop="application_number"
            label="申请号"
            min-width="160"
            sortable="custom"
          ></el-table-column>
          <el-table-column
            show-overflow-tooltip
            key="21"
            prop="type"
            label="专利类型"
            min-width="110"
            sortable="custom"
          >
            <template slot-scope="scope">{{
              scope.row.type | typeFilter
            }}</template>
          </el-table-column>
          <el-table-column
            show-overflow-tooltip
            key="20"
            prop="status"
            label="流程状态"
            min-width="110"
            sortable="custom"
          >
            <template slot-scope="scope">{{ scope.row.status }}</template>
          </el-table-column>
          <el-table-column
            key="26"
            show-overflow-tooltip
            prop="status_submited_at"
            label="提交日期"
            min-width="160"
            sortable="custom"
          >
            <template slot-scope="scope">{{ scope.row | getPost }}</template>
          </el-table-column>
          <el-table-column
            key="27"
            show-overflow-tooltip
            prop="status_updated_at"
            label="更新时间"
            min-width="160"
            sortable="custom"
          >
            <template slot-scope="scope">{{
              scope.row | getAnswerUpdateTime
            }}</template>
          </el-table-column>
          <el-table-column fixed="right" width="140" label="操作">
            <template slot-scope="scope" v-if="getType == 3">
              <el-button
                type="primary"
                size="small"
                @click.stop="appeal(scope.row)"
                :disabled="scope.row.answer_file != ''"
                v-no-more-click:3000
                >上传申诉文件</el-button
              >
            </template>
          </el-table-column>
        </template>
      </el-table>
    </div>
    <div class="myOrder-bottom">
      <pagination
        @paginationChange="paginateChange"
        :total="total"
      ></pagination>
    </div>

    <orderInfo ref="orderInfo" @refresh="getTableData" />
    <submitPeplyFileDialog ref="submitPeplyFileDialog" @refresh="getTableData" />
    <uploadAppeal ref="uploadAppeal" @refresh="getTableData" />
  </div>
</template>

<script>
import Pagination from "~/components/pagination";
import tableSearch from "~/components/tableSearch";
import preImg from "~/components/pre-img";
import orderInfo from "./components/order-info";
import { getMyInfo } from "~/api/user";
import { getTimeConsuming } from "~/util/index";
import orderStatistics from "~/components/orderStatistics";
import submitPeplyFileDialog from "./components/submitPeplyFileDialog";
import uploadAppeal from "./components/upload-appeal";
import Watermark from "./components/watermark";
export default {
  components: {
    Pagination,
    tableSearch,
    preImg,
    orderInfo,
    orderStatistics,
    submitPeplyFileDialog,
    uploadAppeal
  },
  data() {
    return {
      myCaseTotal: 0,
      myReplyTotal: 0,
      myReviewTotal: 0,
      afterTotal: 0,
      isLeaveWord: false,
      showRefund4: false,
      leaveWordText: "",
      privateLetterId: "",
      tableData: [],
      loading: false,
      pageSize: 25, //一页可以几条
      total: 0,
      selectHead: [
        {
          label: "订单编号",
          props: "order_number"
        },
        {
          label: "流程状态",
          props: "status"
        },
        {
          label: "专利类型",
          props: "type",
          order: true
        },
        {
          label: "专属顾问",
          props: "process_id"
        },
        {
          label: "拟申报专利名称",
          props: "patent_name"
        },
        {
          label: "联络人",
          props: "liaisons"
        },
        {
          label: "缴费状态",
          props: "is_payed"
        },
        {
          label: "电话",
          props: "liaisons_tel"
        },
        {
          label: "发明人",
          props: "user_name"
        },
        {
          label: "专利权人",
          props: "patent_user"
        },
        {
          label: "邮箱",
          props: "liaisons_email"
        },
        {
          label: "提交时间",
          props: "subimt_time"
        }
      ],
      selectHeadAnswer: [
        {
          label: "订单编号",
          props: "order_number"
        },
        {
          label: "流程状态",
          props: "status",
          final: true
        },
        {
          label: "专利类型",
          props: "type"
        },
        {
          label: "申请号",
          props: "application_number"
        },
        {
          label: "申报名称",
          props: "name"
        },
        {
          label: "提交日期",
          props: "subimtTime"
        },
        {
          label: "更新时间",
          props: "updated_at"
        }
      ],
      paramsByOrder: {
        status:
          "代理人撰写中,案件内审中,案件修改中,定稿文件发送中,发明人确认定稿中,上报文件上传中,文件格式审核中",
        sort_str: "pick_up_date",
        sort_order: "asc"
      },
      myInfo: {
        agentOrderCount: 0,
        unPaymentCount: 0,
        back_total: 0,
        out_time_orders: 0,
        reply_total: 0,
        reply_overtime: 0
      },
      baseUrl: global.baseurl,
      roleID: 2,
      getType: 1, // 1 我的订单 2 我的答复
      showOrderPay: false,

    };
  },
  watch: {
    tableData: {
      handler: function(val) {
        val.forEach(v => {
          v.imgArr = [];
          v.imgArr2 = [];
          if (v.thumb_imgs) {
            let arr = v.thumb_imgs.split("&");
            if (v.img) {
              let arr = v.img.split("&");
              for (let i in arr) {
                v.imgArr2.push(this.baseUrl + "/storage/upload/" + arr[i]);
              }
            }
            for (let i in arr) {
              v.imgArr.push(this.baseUrl + "/storage/upload/" + arr[i]);
            }
          }
          if (v.review_file) {
            v.reviewfileArr = [];
            let reviewfile = v.review_file.split("&");
            for (let j in reviewfile) {
              let itemobj = {
                id: j + 1,
                path: reviewfile[j],
                file: ""
              };
              let itemArr = itemobj.path.split("/");
              itemobj.path = itemArr[itemArr.length - 1];
              itemobj.file = itemArr.slice(0, 2).join("/");
              v.reviewfileArr.push(itemobj);
            }
          }
          if (v.opinion_file) {
            v.opinionFile = [];
            let reviewfile = v.opinion_file.split("&");
            for (let j in reviewfile) {
              let itemobj = {
                id: j + 1,
                path: reviewfile[j],
                file: ""
              };
              let itemArr = itemobj.path.split("/");
              itemobj.path = itemArr[itemArr.length - 1];
              itemobj.file = itemArr.slice(0, 2).join("/");
              v.opinionFile.push(itemobj);
            }
          }
          if (v.answer_file) {
            v.answerFile = [];
            let reviewfile = v.answer_file.split("&");
            for (let j in reviewfile) {
              let itemobj = {
                id: j + 1,
                path: reviewfile[j],
                file: ""
              };
              let itemArr = itemobj.path.split("/");
              itemobj.path = itemArr[itemArr.length - 1];
              itemobj.file = itemArr.slice(0, 2).join("/");
              v.answerFile.push(itemobj);
            }
          }
        });
      },
      immediate: true
    }
  },
  computed: {
    getTeacherColumns() {
      let columnsData = this.selectHead;
      let item = {
        label: "代理人",
        props: "agent_id"
      };
      if (this.$store.state.user.is_teacher == 1) {
        if (columnsData.findIndex(v => v.label == "代理人")) {
          let index = columnsData.findIndex(v => v.label == "代理人");
          columnsData.splice(index, 1);
        }
        columnsData.splice(3, 0, item);
      }
      return columnsData;
    }
  },
  async created() {
    let myInfo = await getMyInfo(this.$axios);
    if (myInfo.data.status == "success") {
      this.$store.commit("setRoleInfo", myInfo.data.data);
      this.$store.commit("setUser", myInfo.data.data);
      this.getTableData();
    }
  },
  deactivated() {
    this.$destroy(true); //销毁组件
  },
  mounted() {
    let user = JSON.parse(sessionStorage.getItem('store'))
    let name = ''
    if (user) {
      name = user.user.name
    } else {
      name = this.$store.state.user.name || ''
    }
    Watermark.set(name, this.$refs.watermark)
  },
  methods: {
    //跳到国知局页面
    toAfterKnow() {
      this.$router.push("/mechanism/order/afterKnowledge");
    },
    gwm() {
      //水印,非管理员要设置
      if (
        this.$store.state.user.role_id != 1 &&
        this.$route.path != "/admin/register" &&
        this.$route.path != "/admin/personalCenter/dstribution" &&
        this.$route.path != "/admin/personalCenter/myPurse" &&
        this.$route.path != "/admin/activityList/activityConfig" &&
        this.$route.path != "/admin/activityList/sysConfig" &&
        this.$route.path != "/admin/login" &&
        this.$route.path != "/admin/agentImprove" &&
        this.$route.path != "/order/login"
      ) {
        let that = this;
        let gwm = require("gwm");
        gwm.creation({
          txt: that.$store.state.user.name,
          container: ".el-table", //#gwm
          fontSize: 40,
          css: true,
          alpha: 0.3
        });
      }
    },
    tableRowClass({ row, rowIndex }) {
      if (this.getType == 1) {
        if (row.is_frozen == 1 || row.is_frozen == 3) {
          return "row-frozen";
        }
      }
    },
    leaveWordF(row, role) {
      let that = this;
      // this.privateLetterId = row.consumer_id;
      if (role == "l") {
        that.receiver = "发明人";
        that.privateLetterId = row.consumer_id;
      } else {
        that.receiver = "专属顾问";
        that.privateLetterId = row.process_id;
      }
      let params = {
        receive_uid: that.privateLetterId,
        LorD: that.receiver,
        order_number: row.order_number
      };
      if (row.finals_id) {
        params.finals_id = row.finals_id;
      } else {
        params.order_id = row.id;
      }
      that.$alert("即将离开当前页面，去到案件交流", "提示", {
        confirmButtonText: "确定",
        center: true,
        callback: action => {
          if (action != "cancel") {
            that.$router.push({
              path: "/agent/news/communication",
              query: params
            });
          } else {
            that.$message({
              type: "info",
              message: "用户取消跳转"
            });
          }
        }
      });
    },
    leaveWordL(row, role) {
      let that = this;
      // that.privateLetterId = row.process_id;
      if (role == "process") {
        that.receiver = "专属顾问";
        that.privateLetterId = row.process_id;
      } else {
        that.receiver = "发明人";
        that.privateLetterId = row.consumer_id;
      }
      let params = {
        receive_uid: that.privateLetterId,
        LorD: that.receiver,
        order_number: row.order_number
      };
      if (row.finals_id) {
        params.finals_id = row.finals_id;
      } else {
        params.order_id = row.id;
      }
      that.$alert("即将离开当前页面，去到案件交流", "提示", {
        confirmButtonText: "确定",
        center: true,
        callback: action => {
          if (action != "cancel") {
            that.$router.push({
              path: "/agent/news/communication",
              query: params
            });
          } else {
            that.$message({
              type: "info",
              message: "用户取消跳转"
            });
          }
        }
      });
    },
    headGetData(pStatus) {
      if (pStatus == "案件修改中") {
        (this.paramsByOrder.status = "案件修改中"),
          (this.paramsByOrder.page = 1);
        delete this.paramsByOrder.is_time_out;
        delete this.paramsByOrder.is_distribution;
        delete this.paramsByOrder.is_payed;
      }
      if (pStatus == "is_time_out") {
        this.paramsByOrder.status =
          "代理人撰写中,案件内审中,案件修改中,定稿文件发送中,发明人确认定稿中,上报文件上传中,文件格式审核中";
        this.paramsByOrder.is_time_out = 1;
        delete this.paramsByOrder.is_distribution;
        delete this.paramsByOrder.is_payed;
        delete this.paramsByOrder.agent_id;
      }
      if (pStatus == "自提案件") {
        this.paramsByOrder.is_distribution = 3;
        this.paramsByOrder.status =
          "案件内审中,案件修改中,上报文件上传中,文件格式审核中";
        delete this.paramsByOrder.is_time_out;
        delete this.paramsByOrder.is_payed;
        delete this.all_student_order;
        this.showOrderPay = true;
      } else {
        this.showOrderPay = false;
      }

      if (pStatus == "待缴费案件") {
        this.paramsByOrder.is_distribution = 3;
        this.paramsByOrder.status =
          "案件内审中,案件修改中,上报文件上传中,文件格式审核中,等待提交国知局";
        this.paramsByOrder.is_payed = 1;
        delete this.all_student_order;
        delete this.paramsByOrder.is_time_out;
        this.showOrderPay = true;
      } else {
        // this.showOrderPay = false
      }
      this.getTableData();
    },
    async getMyinfo(params) {
      let myInfo = await getMyInfo(this.$axios, params);
      if (myInfo.data.status == "success") {
        this.$store.commit("setRoleInfo", myInfo.data.data);
        this.$store.commit("setUser", myInfo.data.data);
        // this.myInfo = myInfo.data.data;
      }
    },
    switchTable(type) {
      this.tableData = [];
      this.getType = type;
      this.$nextTick(() => {
        this.$refs["tableRef"].doLayout();
      });
      if (type == 1) {
        this.paramsByOrder = {
          status:
            "代理人撰写中,案件内审中,案件修改中,定稿文件发送中,发明人确认定稿中,上报文件上传中,文件格式审核中",
          sort_str: "pick_up_date",
          sort_order: "asc",
          page: 1
        };
      } else if (type == 2) {
        this.paramsByOrder = {
          status: "等待答复,等待补正,发明人确认答复中,发明人确认补正中",
          agent_id: this.$store.state.user.id,
          page: 1
        };
      } else {
        this.paramsByOrder = {
          status: "申诉中",
          agent_id: this.$store.state.user.id,
          page: 1
        };
      }

      this.getTableData();
    },
    
    getTableData(args) {
      let params = {
        perPage: this.pageSize,
        page: this.currentPage
      };
      params = { ...params, ...this.paramsByOrder, ...this.search_params };
      if (args) {
        params = { ...params, ...args };
      }
      let url = "api/order";
      if (this.getType == 1) {
        if (this.$store.state.user.is_teacher == 2) {
          params.student_order = true;
          params.agent_id = this.$store.state.user.id;
        } else if (this.$store.state.user.is_teacher == 1) {
          if (!params.agent_id) {
            params.all_student_order = true;
            if (params.is_distribution == 3) {
              params.agent_id = this.$store.state.user.id;
              delete params.all_student_order;
            }
          } else {
            delete params.all_student_order;
          }
        } else {
          params.agent_id = this.$store.state.user.id;
        }
        url = "api/order";
      } else {
        url = "api/finals";
      }

      this.loading = true;
      this.$axios
        .get(url, {
          params: params
        })
        .then(res => {
          if (res.data.code == 200) {
            this.loading = false;
            this.tableData = res.data.data;
            this.pageSize = res.data.page.per_page;
            this.total = res.data.page.total;
            this.myInfo = res.data.count;
            this.myReplyTotal = res.data.count.reply_total;
            this.myReviewTotal = res.data.count.reexamine;
            this.afterTotal = res.data.count.finalsCount
            this.myCaseTotal = res.data.count.myOrder
            // this.getMyinfo();
          } else {
            this.loading = false;
            this.$message.error("服务器繁忙");
          }
        });
    },

    searchMethods(params, no_search) {
      this.sort_params = {};
      this.currentPage = 1;
      this.pageSize = 25;
      this.search_params = params;
      if (params.subimt_time) {
        params.start_time = params.subimt_time[0];
        params.end_time = params.subimt_time[1];
        delete params.subimt_time;
      }
      if (params.subimtTime) {
        params.status_submited_at_start = params.subimtTime[0];
        params.status_submited_at_end = params.subimtTime[1];
        delete params.subimtTime;
      }
      if (params.updated_at) {
        params.status_updated_at_start = params.updated_at[0];
        params.status_updated_at_end = params.updated_at[1];
        delete params.updated_at;
      }
      if (!no_search) {
        this.getTableData();
      }
    },
    paginateChange(params) {
      this.pageSize = params.perPage;
      this.currentPage = params.page;
      this.getTableData();
    },
    tableSortChange(column) {
      if (column.order === "descending") {
        this.paramsByOrder.sort_str = column.prop;
        this.paramsByOrder.sort_order = "desc";
      } else if (column.order === "ascending") {
        this.paramsByOrder.sort_str = column.prop;
        this.paramsByOrder.sort_order = "asc";
      } else {
        delete this.paramsByOrder.sort_str;
        delete this.paramsByOrder.sort_order;
      }
      this.loading = true;
      this.currentPage = 1;
      this.getTableData();
    },
    // 处理时长
    getProcessingTime(value) {
      //获取接单的时间戳
      // createDay = createDay.replace(/-/g, "/");
      let createTime = new Date(value).getTime();
      //获取当前的时间戳
      var nowTime = new Date().getTime();
      //获取处理时间戳
      let cha = nowTime - createTime;

      function IsNaN(value) {
        return typeof value === "number" && isNaN(value);
      }
      if (IsNaN(cha)) {
        return "";
      }

      //转换天数
      let round2 = (cha / 1000 / 60 / 60 / 24).toFixed(2);
      let processingTime = (Math.ceil(round2 * 10) / 10).toFixed(1);

      if (processingTime < 0) {
        return "0.0";
      } else if (processingTime < 0.1) {
        return "0.1";
      } else {
        return processingTime;
      }
    },
    selectRow(row) {
      if (this.getType == 1) {
        if (window.getSelection().toString() === "") {
          this.$refs["orderInfo"].show(row);
        }
      }
    },

    getTimeConsuming(val) {
      return getTimeConsuming(val);
    },

    answer(row) {
      this.$refs["submitPeplyFileDialog"].show(row);
    },
    // 上传申诉文件
    appeal(row) {
      this.$refs["uploadAppeal"].show(row);
    }
  }
};
</script>

<style lang="less" scoped>
.myOrder {
  width: 90%;
  height: 100%;
  margin: 0 auto;
  padding: 25px 30px 0 30px;
  background: #fff;
  display: flex;
  flex-direction: column;
  .el-table__body-wrapper {
    // opacity: 0.7;
  }
  &-header {
    // height: 45px;
    flex: 0 0 45px;
    /deep/.el-breadcrumb {
      margin-bottom: 10px;
      height: 40px;
      .el-breadcrumb__item {
        line-height: 40px;
        .el-breadcrumb__inner,
        .el-breadcrumb__separator {
          font-size: 25px;
          color: rgba(0, 35, 151, 1);
          font-weight: 400;
        }
      }
      .el-breadcrumb__item:first-child {
        .el-breadcrumb__inner {
          padding-left: 10px;
          border-left: 5px solid #002397;
        }
      }
    }
    box-sizing: border-box;
    .btns {
      line-height: 40px;
      .el-button {
        border: 1px solid #249dff;
        border-radius: 12px;
        padding: 5px 16px;
        display: inline-block;
        font-size: 15px;
        line-height: 1;
        color: #249dff;
        margin: 0 20px 10px 0;
      }

      .el-button:hover {
        background: rgba(36, 157, 255, 1);
        color: #fff;
      }
    }
    .table-search {
      margin-bottom: 10px;
    }
    .addAgentOrder {
      background: #58a5ea;
      color: #fff;
    }
  }
  &-main {
    flex: 1;
    max-height: calc(100% - 115px);
  }
  &-bottom {
    flex: 0 0 70px;
    padding-top: 19px;
  }
  .file_sh {
    font-size: 25px;
    margin-right: 10px;
  }
}
.leaveWordDialog {
  width: 50%;
  margin: auto;
  .leaveWord-label {
    display: block;
    margin-bottom: 10px;
  }
  .el-textarea {
    display: block;
    margin-bottom: 20px;
  }
}
</style>
